import { runCommand } from ".";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        runCommand(context, options, isUndo, (sheet, options) => {
            const { formatter:{formatter,formatterType} } = options;
            sheet.getSelections().forEach(selection => {
                sheet.getRange(selection.row, selection.col, selection.rowCount, selection.colCount).formatter(formatter);
                for (let r = selection.row; r < selection.row + selection.rowCount; r++) {
                    for (let c = selection.col; c < selection.col + selection.colCount; c++) {
                        const cell = sheet.getCell(r, c);
                        const tag = cell.tag() || {};
                        cell.tag({ ...tag, formatterType,formatter });
                    }
                }
            });
        })
    }
};